package com.ha8.netease.views.team.mail
{
	import com.ha8.netease.PrivateNotify;
	import com.ha8.netease.models.WeiboProxy;
	import com.ha8.netease.models.vo.MailReqVO;
	import com.ha8.netease.views.utils.DataUtil;
	import com.rogo.mvc.interfaces.INotification;
	import com.rogo.mvc.sub.mediator.Mediator;
	
	import mx.collections.ArrayCollection;
	
	public class ReceiveMailMediator extends Mediator
	{
		public function ReceiveMailMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		public static const NAME:String = 'receiveMailMediator';
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		
		private var vo:MailReqVO;
		private var displayMails:ArrayCollection;
		
		//--------------------------------------------------------------------------
		//
		//  Overridden Methods
		//
		//--------------------------------------------------------------------------
		
		override public function onRegister():void
		{
			displayMails = new ArrayCollection();
			view.dataGroup.dataProvider = displayMails;
			
			vo = new MailReqVO();
			requestData();
		}
		
		override public function listNotificationInterests():Array
		{
			return [PrivateNotify.GET_MAIL_ERROR,
				PrivateNotify.GET_MAIL_RESULT];
		}
		
		override public function notificationHandler(notification:INotification):void
		{
			switch (notification.name)
			{
				case PrivateNotify.GET_MAIL_RESULT:
					updateData(notification.param as ArrayCollection);
					break;
				case PrivateNotify.GET_MAIL_ERROR:
					break;
			}
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function get view():ReceiveMail
		{
			return viewComponent as ReceiveMail;
		}
		
		public function get proxy():WeiboProxy
		{
			return facade.retrieveProxy(WeiboProxy.NAME) as WeiboProxy;
		}
		
		private function requestData():void
		{
			proxy.getMail(vo);
		}
		
		private function updateData(data:ArrayCollection):void
		{
			DataUtil.merge(displayMails, data);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//--------------------------------------------------------------------------
		
	}
}